package objects
{
	import core.Assets;
	
	import flash.geom.Rectangle;
	
	import starling.core.Starling;
	import starling.display.Image;
	import starling.display.Shape;
	import starling.display.Sprite;
	import starling.events.Event;
	import starling.extensions.PDParticleSystem;
	
	import states.Play;
	
	public class Hero extends Sprite
	{
		public var displayBounds:Shape;
		
		private var _play:Play;
		private var _heroImage:Image;
		private var _smallBounds:Rectangle;
		private var _smallBoundsFactor:uint;
		private var _smokePS:PDParticleSystem;
		private var _moveSpeed:uint;
		private var _easing:Number;
		
		public function Hero(play:Play)
		{
			trace("Hero initialized.");
			
			super();
			
			this._play = play;
			
			this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
		}
		
		public function update(deltaSmall:Number):void
		{
			
		}
		
		public function destroy():void
		{
			_play.removeChild(_smokePS);
			Starling.juggler.remove(_smokePS);
			_smokePS.dispose();
			_smokePS = null;
			
			_play = null;
			this.removeChild(_heroImage);
			_heroImage.dispose();
			this.removeFromParent(true);
			_smallBounds = null;
		}
		
		private function onAddedToStage():void
		{
			this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
			
			_heroImage = new Image(Assets.atlasTexture.getTexture("player"));
			this.addChild(_heroImage);
			_heroImage.pivotX = _heroImage.width * 0.5;
			_heroImage.pivotY = _heroImage.height * 0.5;
			
			_smokePS = new PDParticleSystem(XML(new Assets.SmokeParticleXML()), Assets.atlasTexture.getTexture("smoke"));
			Starling.juggler.add(_smokePS);
			_play.addChild(_smokePS);
			_smokePS.start();
			
			_moveSpeed = 100;
			_easing = 0.1;
			
			_smallBoundsFactor = 20;
			createSmallBounds();
		}
		
		private function createSmallBounds():void
		{
			_smallBounds = new Rectangle(this.bounds.x + (_smallBoundsFactor * 0.5),
				this.bounds.y + (_smallBoundsFactor * 0.5),
				this.bounds.width - _smallBoundsFactor, 
				this.bounds.height - _smallBoundsFactor);
			
			/*displayBounds = new Shape();
			displayBounds.graphics.lineStyle(1, 0xff);
			displayBounds.graphics.drawRect(this.bounds.x + 10, this.bounds.y + 10, this.bounds.width - 20, this.bounds.height - 20);
			displayBounds.graphics.endFill();
			this.addChild(displayBounds);*/
		}

		public function get smallBounds():Rectangle
		{
			return _smallBounds;
		}

		public function set smallBounds(value:Rectangle):void
		{
			_smallBounds = value;
		}

		public function get smokePS():PDParticleSystem
		{
			return _smokePS;
		}

		public function get moveSpeed():uint
		{
			return _moveSpeed;
		}

		public function set moveSpeed(value:uint):void
		{
			_moveSpeed = value;
		}

		public function get easing():Number
		{
			return _easing;
		}

		public function set easing(value:Number):void
		{
			_easing = value;
		}


	}
}



































